{% extends 'AdminPanelDashboardBundle::layout.html.twig' %}


{% block stylesheets %}
  {{ parent() }}
{% endblock %}

{% block javascripts %}
{{ parent() }}
<!-- jQuery Validate -->
<script src="/adminTemplate/theme/scripts/jquery-validation/dist/jquery.validate.min.js" type="text/javascript"></script>
<script src="/adminTemplate/theme/scripts/form_validator.js" type="text/javascript"></script>
<script>

$( document ).ready(function() {
  
  callRadioClick();
  
});

function callRadioClick()
{
  $(".is_correct").click(function(){
    $(this).val($(this).prev().val());    
  })
  
}

function addQuestion()
{
  var lineNUmber = parseInt($("#lineNumber").val());
  lineNUmber = lineNUmber + 1;  
  $(".questionContainer:last").after('<div class="control-group questionContainer" id="questionContainer_'+lineNUmber+'"><label class="control-label"><a href="javascript:;" onclick="removeLine('+lineNUmber+')">Хасах</a></label><div class="controls"><textarea class="answers" name="answers[]" ></textarea><input type="radio" name="is_correct" class="is_correct" value=""></input></div></div>');
  $("#lineNumber").val(lineNUmber);
  callRadioClick();
}

function removeLine(chosenLine)
{
  $("#questionContainer_"+chosenLine).remove();
  var lineNUmber = parseInt($("#lineNumber").val());
  lineNUmber = lineNUmber - 1;
  $("#lineNumber").val(lineNUmber);
}

  </script>
{% endblock %}

{% block content %}

<div id="content">
  <ul class="breadcrumb">
    <li><a href="index.php" class="glyphicons home"><i></i> Нүүр</a></li>
    <li class="divider"></li>
    <li><a href="{{path('admin_question')}}">Асуулт</a></li>
    
    
  </ul>
  <div class="separator"></div>

  <h3 class="glyphicons show_thumbnails_with_lines"><i></i> Шалгалт</h3>
  <div class="separator"></div>

  <form class="form-horizontal" style="margin-bottom: 0;" id="contentEditForm" action="{{ path('admin_question_update', {'id':entity.id}) }}" method="post" {{ form_enctype(form) }} autocomplete="off">

    <div class="well" style="padding-bottom: 20px; margin: 0;">
      <h4>Шалгалтын асуулт засах</h4>
      <hr class="separator" />
      <div class="row-fluid">
        <div class="span6" style="width: 90%">                    

          <div class="control-group">  
            <div class="widget-body" style="padding: 10px 0 0;">              
              {{ form_label(form.question, label|default(null), { 'label_attr': { 'class': 'control-label' } }) }}
                <div class="controls">{{ form_widget(form.question, { 'attr': {'class': 'wysihtml5 span12', 'rows' : '5'} }) }}</div>              
              </div>
            </div>

            <div class="control-group">                
                {{ form_label(form.isActive, label|default(null), { 'label_attr': { 'class': 'control-label' } }) }}
                <div class="controls">{{ form_widget(form.isActive, { 'attr': {'class': 'span12'} }) }}</div>
              </div>

              <div class="control-group">                
            {{ form_label(form.sortOrder, label|default(null), { 'label_attr': { 'class': 'control-label' } }) }}
                  <div class="controls">{{ form_widget(form.sortOrder, {'id' : 'sortOrder', 'attr': {'class': 'span12'} }) }}</div>
                </div>

                <div class="control-group">                
             {{ form_label(form.showType, label|default(null), { 'label_attr': { 'class': 'control-label' } }) }}
                    <div class="controls">{{ form_widget(form.showType, { 'attr': {'class': 'span12'} }) }}</div>
                  </div>

                  <div class="control-group">                
             {{ form_label(form.questionType, label|default(null), { 'label_attr': { 'class': 'control-label' } }) }}
                      <div class="controls">{{ form_widget(form.questionType, { 'attr': {'class': 'span12'} }) }}</div>
                    </div>      
                    <hr class="separator" />

                    <div class="control-group">                
                      <label class="control-label"><h4 style="width: 120px;">Хариулт </h4></label>
                      <div class="controls"><a href="javascript:;" onclick="addQuestion()">Нэмэх</a><input type="hidden" value="{% if count is not null %}{{count}}{% else %}1{% endif %}" id="lineNumber" name="lineNumber"/></div>
                    </div>
                    {% set counter = 1 %}
                    {% set radioValues = 0 %}
                    
                    {% if count is not null %}
                    
                        {% for question in questionArray %}
                        <div class="control-group questionContainer" id="questionContainer_{{counter}}">
                          <label class="control-label"><a href="javascript:;" onclick="removeLine({{counter}})">Хасах</a></label>
                          <div class="controls"><textarea class="answers" name="answers[]">{{question.answer}}</textarea><input type="radio" name="is_correct" class="is_correct" value="" {% if question.is_correct is not null %}checked{% endif %}></input></div>
                        </div>
                        {% set counter = counter + 1 %}
                        {% set radioValues = radioValues + 1 %}

                        {% endfor %}
                    {% else %}                    
                    <div class="control-group questionContainer" id="questionContainer_1">                
                      <label class="control-label"></label>
                      <div class="controls">
                          <textarea name="answers[]" class="answers"></textarea>
                          <input type="radio" name="is_correct" class="is_correct" value=""></input></div>
                    </div>
                    {% endif %}
                    <div class="form-actions">
                      <button type="submit" class="btn btn-icon btn-primary glyphicons circle_ok"><i></i>Хадгалах</button>
                      <a href="{{ path('admin_question') }}"><button type="button" class="btn btn-icon btn-default glyphicons circle_remove"><i></i>Буцах</button></a>
                    </div>
                  </div>
{{ form_widget(form._token) }}
                  </form>
                  <!-- End Content -->
                </div>

{% endblock %}
